package com.ruoyi.zsix.service.manager;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.zsix.domain.process.ProcessManage;
import com.ruoyi.zsix.domain.taskAssignee.GenerWork;
import com.ruoyi.zsix.mapper.processMapper.ProcessManageMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Component
@RequiredArgsConstructor
public class IProcessMManager {
    @Autowired
    private ProcessManageMapper processManageMapper;
    /**
     * 获取当前系统登陆人发起的流程列表
     * @param title
     * @param flowName
     * @param state
     * @param page
     * @param pagesize
     * @return
     */
    public HashMap<String,Object> getMyStartList(String title, String flowName, String state,
                                                 Integer page, Integer pagesize){
        HashMap<String,Object> hashMap=new HashMap<>();
        HashMap<String,Object> pieMap=new HashMap<>();
        List<HashMap<String,Object>> pieData=new ArrayList<>();
        List<ProcessManage> processManages=processManageMapper.getMyStartList(title,flowName,state,
                SecurityUtils.getUsername());

        List<ProcessManage> RefuseList=processManageMapper.getMyStartRefuseList(SecurityUtils.getUsername());
        if(pagesize==0){
            hashMap.put("total",processManages.size());
            hashMap.put("list",processManages);
        }
        else{
            Integer startIndex=(page-1)*pagesize;
            List<ProcessManage> processManageList=processManageMapper.getMyStartListPage(title,flowName,state,
                    SecurityUtils.getUsername(),startIndex,pagesize);

            hashMap.put("total",processManages.size());
            hashMap.put("list",processManageList);
        }
        pieMap.put("name","审核通过");
        pieMap.put("value",(processManages.size()-RefuseList.size()));
        pieData.add(pieMap);

        pieMap=new HashMap<>();
        pieMap.put("name","被拒绝");
        pieMap.put("value",RefuseList.size());
        pieData.add(pieMap);

        hashMap.put("processManages",processManages.size()-RefuseList.size());
        hashMap.put("refuseList",RefuseList.size());
        hashMap.put("pieData",pieData);
        return hashMap;
    }
    /**
     * 获取我审核的数据
     * @param title
     * @param flowName
     * @param state
     * @param page
     * @param pagesize
     * @return
     */
    public HashMap<String,Object> getMyProcessPage(String title, String flowName, String state,
                                                   Integer page, Integer pagesize){
        HashMap<String,Object> hashMap=new HashMap<>();
        HashMap<String,Object> pieMap=new HashMap<>();
        List<HashMap<String,Object>> pieData=new ArrayList<>();
        List<GenerWork> processManages=processManageMapper.getMyProcessList(SecurityUtils.getUsername(),state,flowName,title);;

        List<GenerWork> RefuseList=processManageMapper.getMyProcessRefuse(SecurityUtils.getUsername());
        if(pagesize==0){
            hashMap.put("total",processManages.size());
            hashMap.put("list",processManages);
        }
        else{
            Integer startIndex=(page-1)*pagesize;
            List<GenerWork> processManageList=processManageMapper.getMyProcessPage(SecurityUtils.getUsername(),state,title,startIndex,pagesize,flowName);

            hashMap.put("total",processManages.size());
            hashMap.put("list",processManageList);
        }
        pieMap.put("name","审核通过");
        pieMap.put("value",(processManages.size()-RefuseList.size()));
        pieData.add(pieMap);

        pieMap=new HashMap<>();
        pieMap.put("name","被拒绝");
        pieMap.put("value",RefuseList.size());
        pieData.add(pieMap);

        hashMap.put("processManages",processManages.size()-RefuseList.size());
        hashMap.put("refuseList",RefuseList.size());
        hashMap.put("pieData",pieData);
        return hashMap;
    }
}
